package pe.gob.osinergmin.interfase_siaf.dac.common.dao.impl;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import pe.gob.osinergmin.interfase_siaf.dac.common.dao.IntfLogDao;
import pe.gob.osinergmin.interfase_siaf.dac.domain.interfase.IntfLog;

@Repository("intfLogDao")
public class IntfLogDaoImpl implements IntfLogDao {
	
    private final Log logger = LogFactory.getLog(getClass());
 	
	
	private NamedParameterJdbcTemplate jdbcParameterTemplateInterfase;	
	//private JdbcTemplate jdbcTemplateInterfase;		
	
	
	@Autowired
	public void SetDataSource(DataSource dataSourceInterfase){
		//this.jdbcTemplateInterfase = new JdbcTemplate(dataSourceInterfase);
		this.jdbcParameterTemplateInterfase = new NamedParameterJdbcTemplate(dataSourceInterfase);		
	}
	
	
	
	/**DECLARACION DE SQL**/	
	private static final String SQL_INSERT_INTF_LOG ="INSERT INTO INTF_LOG (TIPO,INTERFASE,SECUENCIAL,TABLA,CAMPO,VALOR,"
			+ " MENSAJE)  VALUES (:tipo, :interfase, :secuencial, :tabla, :campo, :valor, :mensaje)";
	
	
	/**IMPLEMENTACION DE METODOS*/
	
	@Override
	public void insertarIntfLog(IntfLog intfLog) throws Exception{
		logger.info("Ingresando a insertar intfLog"); 
		SqlParameterSource parameters = new BeanPropertySqlParameterSource(intfLog);
		int ok = this.jdbcParameterTemplateInterfase.update(SQL_INSERT_INTF_LOG, parameters);
		logger.info("insertar intfLog OK :  " + ok); 
	}

}
